﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Zocono.WCS.Domain.EquipmentProcessDomain
{
    public class PlanarMessageServiceFactory : IPlanarMessageServiceFactory
    {
        private readonly IEnumerable<IPlanarActionMessageService> _servicesState;
        private readonly IEnumerable<IPlanarStateMessageService> _servicesAction;

        public PlanarMessageServiceFactory(IEnumerable<IPlanarActionMessageService> servicesState, IEnumerable<IPlanarStateMessageService> servicesAction)
        {
            _servicesState = servicesState;
            _servicesAction = servicesAction;
        }

        public IPlanarActionMessageService CreateActionService(string objectType)
        {
            //var type = Assembly.GetAssembly(typeof(PlanarMessageServiceFactory)).GetType($"Zocono.WCS.Domain.EquipmentProcessDomain.{objectType}MessageService");
            //var instance = _provider.GetService(type);
            //return instance as IPlanarActionMessageService;
            string serviceName = $"{objectType}MessageService";
            var instance = _servicesState.SingleOrDefault(s => s.GetType().Name == serviceName);
            return instance;
        }

        public IPlanarStateMessageService CreateStateService(string objectType)
        {
            //var type = Assembly.GetAssembly(typeof(PlanarMessageServiceFactory)).GetType($"Zocono.WCS.Domain.EquipmentProcessDomain.{objectType}MessageService");
            //var instance = _provider.GetService(type);
            //return instance as IPlanarStateMessageService;
            string serviceName = $"PlanarStateMessageService";
            var instance = _servicesAction.SingleOrDefault(s => s.GetType().Name == serviceName);
            return instance;
        }
    }
}
